<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>修改密码--后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all" />
    <link rel="stylesheet" th:href="@{/static/fonts/iconfont.css}" media="all"/>
    <style type="text/css">
        .layui-form-item .layui-inline {
            min-width: 15%;
            float: left;
            margin-right: 0;
        }

        .layui-form-item .role-box {
            position: relative;
        }

        body {
            margin: 0px;
            padding: 0px;
            background-color: #d2d2d2;
        }

        .layui-card {
            margin-top: 10px;
        }
        .nameTitle{
            font-size: large;
            font-style: inherit;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <form class="layui-form changePwd"  th:method="post" enctype="multipart/form-data;charset=UTF-8">
        <div class="layui-row">
            <div class="layui-row layui-col-space12">
                <div class="layui-col-md6 layui-col-md-offset3">
                    <div class="layui-card">
                        <div class="layui-card-header nameTitle">修改密码</div>
                        <div class="layui-card-body">
                            <div class="layui-row">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">用户名:</label>
                                    <div class="layui-input-block">
                                        <input type="text" th:value="(${#strings.isEmpty(currentUser.nickName)}) ? ${currentUser.loginName} : ${currentUser.nickName}" disabled class="layui-input layui-disabled">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">旧密码:</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="oldPwd" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">新密码:</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="newPwd" placeholder="请输入新密码" lay-verify="required|newPwd" id="oldPwd" class="layui-input pwd">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">确认密码:</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="confirmPwd" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd">
                                    </div>
                                </div>
                                <div class="layui-form-item" style="padding-left: 30%;">
                                    <div class="layui-input-block">

                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                        <button class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" th:src="@{/static/layui/layui.js}"></script>
<script>
    layui.use(['form','jquery','layer'],function(){
        var form = layui.form,
            $    = layui.jquery,
            layer = layui.layer;

        //添加验证规则
        form.verify({
            newPwd : function(value, item){
                if(value.length < 6){
                    return "密码长度不能小于6位";
                }
            },
            confirmPwd : function(value, item){
                if(!new RegExp($("#oldPwd").val()).test(value)){
                    return "两次输入密码不一致，请重新输入！";
                }
            }
        });

        form.on("submit(changePwd)",function(data){
            $.post("/admin/system/user/changePassword",data.field,function(res){
                if(res.success){
                    layer.msg("密码修改成功,请重新登录",{"time":1000},function(){
                        sessionStorage.clear();
                        localStorage.clear();
                        parent.location.href = "/systemLogout";
                    })
                }else{
                    layer.msg(res.message);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>